package net.keebook.webapp.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class DateUtil {	
	public static Date getUtcTimestamp(TimeZone systemTimeZone) {
		Calendar c = Calendar.getInstance();
		c.add(Calendar.SECOND, (-1)*systemTimeZone.getOffset(c.getTimeInMillis())/1000);
		return c.getTime();
	}
	
	public static String getLocalFormattedDateFromUtcTimestamp(Date date, TimeZone localTimezone, String pattern) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		c.add(Calendar.SECOND, localTimezone.getOffset(c.getTimeInMillis())/1000);
		SimpleDateFormat formatter = new SimpleDateFormat(pattern);
		return formatter.format(c.getTime());
	}
	
	public static String getSystemMilliTime() {
		SimpleDateFormat formatter = new SimpleDateFormat("H:m:s:S");
		return formatter.format(new Date());
	}
}
